package com.gxa.eshop.portal.config;


import com.gxa.eshop.portal.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//3. 在配置类中注册拦截器
@Configuration
public class InterceptoerConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器对象, 通过注册的方式
        // 必须通过调用GetTokenInterceptor方法(含有@Bean注解,被Spring管理)
        registry.addInterceptor(GetTokenInterceptor())
                .addPathPatterns("/cart/**")
                .addPathPatterns("/order/**");
    }

    @Bean
    public TokenInterceptor GetTokenInterceptor(){
        return new TokenInterceptor();
    }


}